
#include "TEString.h"
#include "TEDefs.h"
#include <sstream>

wchar_t str[512];

//
// GetInt
//

int GetInt(const string &str)
{
	istringstream iStream(str);

	int i;
	if(iStream>>i) return i;
	return INT_MAX;
}

//
// GetFloat
//

float GetFloat(const string &str)
{
	istringstream iStream(str);

	float f;
	if(iStream>>f) return f;
	return 1.0e10f;
}

//
// Tokenize
//

void Tokenize(const string& str,
              vector<string>& tokens,
              const string& delimiters)
{
	// Skip delimiters at beginning.
	string::size_type lastPos = str.find_first_not_of(delimiters, 0);
	// Find first "non-delimiter".
	string::size_type pos = str.find_first_of(delimiters, lastPos);

	while (string::npos != pos || string::npos != lastPos)
	{
		// Found a token, add it to the vector.
		tokens.push_back(str.substr(lastPos, pos - lastPos));
		// Skip delimiters.  Note the "not_of"
		lastPos = str.find_first_not_of(delimiters, pos);
		// Find next "non-delimiter"
		pos = str.find_first_of(delimiters, lastPos);
	}
}

void Tokenize(const wstring& str,
              vector<wstring>& tokens,
              const wstring& delimiters)
{
	// Skip delimiters at beginning.
	string::size_type lastPos = str.find_first_not_of(delimiters, 0);
	// Find first "non-delimiter".
	string::size_type pos = str.find_first_of(delimiters, lastPos);

	while (string::npos != pos || string::npos != lastPos)
	{
		// Found a token, add it to the vector.
		tokens.push_back(str.substr(lastPos, pos - lastPos));
		// Skip delimiters.  Note the "not_of"
		lastPos = str.find_first_not_of(delimiters, pos);
		// Find next "non-delimiter"
		pos = str.find_first_of(delimiters, lastPos);
	}
}

//
// ConvertToTChar
//

wchar_t *ConvertToTChar(const string &_str)
{
	const char *_cStr = _str.c_str();
	uint i = 0;
	for(i; i < _str.size() && i < 511; i++)
		str[i] = (wchar_t)_cStr[i];
	str[i] = '\0';
	return str;
}